package com.zrrd.jt_admin.order.controller;


import com.zrrd.jt_admin.common.response.ResponseResult;
import com.zrrd.jt_admin.common.vo.OrderPageVo;
import com.zrrd.jt_admin.order.service.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ZhangYK
 * @since 2024-07-04
 */
@Api(tags = "订单管理-接口文档")
@RestController
@RequestMapping("admin/order")
@ResponseBody
public class OrderController {

    @Resource
    private OrderService orderService;

    ///admin/order/:page?limit=[:limit]&
    // tab=[:tab]&no=[:no]&starttime=[:starttime]&
    // endtime=[:endtime]&name=[:name]&phone=[:phone]
    @ApiOperation(value = "一、订单列表")
    @GetMapping("{page}")
    public OrderPageVo findByPage(@PathVariable("page") Integer page,
                                  @RequestParam(value = "limit",required = false,defaultValue = "5") Integer limit,
                                  @RequestParam(value = "tab") String tab,
                                  @RequestParam(value = "no",required = false,defaultValue = "") String no,
                                  @RequestParam(value = "startTime",required = false,defaultValue = "")String startTime,
                                  @RequestParam(value = "endTime",required = false,defaultValue = "")String endTime,
                                  @RequestParam(value = "name",required = false,defaultValue = "")String name,
                                  @RequestParam(value = "phone",required = false,defaultValue = "")String phone) {

        OrderPageVo orderPageVo = orderService.findByPage(page,limit,tab,no,startTime,endTime,name,phone);

        return orderPageVo;
    }

    @ApiOperation(value = "二、批量删除订单")
    @DeleteMapping("/deleteAll")
    public ResponseResult deleteAll(@RequestBody List<Integer> ids) {
        boolean flag = orderService.removeByIds(ids);
        return ResponseResult.removeResponse(flag);
    }

    @ApiOperation(value = "三、订单发货")
    @PostMapping("{id}/ship")
    public ResponseResult ship(@PathVariable("id") Integer id,
                               @RequestParam("expressCompany") String expressCompany,
                               @RequestParam("expressNo")String expressNo) {
        return null;
    }

    @ApiOperation(value = "四、拒绝or同意退款")
    @PostMapping("{id}/handleRefund")
    public ResponseResult handleRefund(@PathVariable("id")Integer id,
                                       @RequestParam("agree")Integer agree,
                                       @RequestParam(value = "disagreeReason",required = false,defaultValue = "")String disagreeReason){
        return null;
    }


}

